<template>
  <div class="classQueryRes">
    <el-breadcrumb separator="/" class="breadcrumb-bottom">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>毕业设计</el-breadcrumb-item>
      <el-breadcrumb-item>教研室查看分配结果</el-breadcrumb-item>
    </el-breadcrumb>
    <el-row :gutter="20" class="mb-12">
      <el-col :span="5">
        <div class="">
          <el-select v-model="graduationResForm.majorID" placeholder="请选择专业" class="full-line">
            <el-option v-for="item in majorData" :label="item.majorName" :value="item.majorID"></el-option>
          </el-select>
        </div>
      </el-col>
      <el-col :span="5">
        <div class="">
          <el-date-picker
            @change="changeAcademicYear"
            v-model="graduationResForm.academicYear"
            type="year"
            class="max-width"
            placeholder="请选择学年">
          </el-date-picker>
        </div>
      </el-col>
      <el-col :span="2">
        <div>
          <el-button type="primary" @click="search">立即搜索</el-button>
        </div>
      </el-col>
      <el-button type="primary" class="float-right add-pd-26" @click.native.prevent="downloadFile">导出</el-button>
    </el-row>
    
  
    <el-table
      :data="classResTable"
      style="width: 100%"
    >
      <el-table-column
        prop="graduateTitle"
        label="课题名称"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="titleSource"
        label="课题来源"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="number"
        label="要求人数"
        min-width="100">
      </el-table-column>
      <el-table-column
        prop="itemCategoryName"
        label="项目类别名称"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="itemCategoryID"
        label="项目类别编号"
        min-width="120">
      </el-table-column>
      <el-table-column
        label="课题附件"
        min-width="120">
        <template scope="scope">
          <el-button
            @click.native.prevent="showAttachment(scope.row.titleAttachment)"
            type="text">
            {{scope.row.titleAttachmentName}}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column
        label="学生"
        min-width="120">
        <template scope="scope">
          <el-button
            @click="checkResults(scope.row.graduateProgramID)"
            type="text">
            查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="paging">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
    <el-dialog title="学生信息" v-model="dialogTableVisible">
      <el-table :data="studentData">
        <el-table-column property="studentName" label="学生姓名" width="150"></el-table-column>
        <el-table-column property="studentID" label="学号" width="200"></el-table-column>
        <el-table-column property="className" label="班级"></el-table-column>
        <el-table-column property="phone" label="联系方式"></el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
<script>
  export default{
    name: 'classQueryRes',
    data(){
      return {
        graduationResForm: {
          majorID: '',
          academicYear: ''
        },
        classResTable: [
          {
            graduateProgramID: '',
            graduateTitle: '',
            titleSource: '',
            itemCategoryID: '',
            itemCategoryName: '',
            teacherName: '',
            number: '',
            titleAttachment: '',
            titleAttachmentName: ''
          }
        ],
        studentData: [{
          studentName: '',
          studentID: '',
          className: '',
          phone: ''
        }],
        majorData: [],
        page: 1,
        pageSize: 10,
        pageSizes: [10, 20, 30, 40],
        total: 40,
        dialogTableVisible: false,
        apiUrl: this.$until.url + '/graduateProgram/getGraduateInfoStaff',
        initUrl: this.$until.url + '/courseDesign/getMajorDesign',
        checkUrl: this.$until.url + '/graduateProgram/getStudentInfo'
      }
    },
    mounted: function () {
      this.$nextTick(function () {
        this.init();
      });
    },
    methods: {
      init(){
        this.res();
        this.gerMajorInfo();
      },
      res(){
        this.$http.get(this.apiUrl, {
            params: {
              page: this.page,
              pageSize: this.pageSize
            }
          }
        ).then((res) => {
          this.total = res.body.totalNum.totalNum;
          this.classResTable = res.body.program
        }, (err) => {
          console.log(err);
        })
      },
      gerMajorInfo(){
        this.$http.get(this.initUrl)
          .then((res) => {
            this.majorData = Array.from(res.body);
          }, (err) => {
            console.log(err)
          })
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        console.log(`当前页: ${val}`);
      },
      search(){
        this.$http.post(this.apiUrl, this.graduationResForm, {
            params: {
              page: this.page,
              pageSize: this.pageSize
            },
            emulateJSON: true
          }
        ).then((res) => {
          this.total = res.body.totalNum.totalNum;
          this.classResTable = res.body.program
        }, (err) => {
          console.log(err);
        })
      },
      checkResults(graduateProgramID){
        this.$http.get(this.checkUrl, {
            params: {
              graduateProgramID: graduateProgramID,
            }
          }
        ).then((res) => {
          this.studentData = res.body;
          this.dialogTableVisible = true
        }, (err) => {
          console.log(err);
        })
      },
      changeAcademicYear: function (val) {
        this.graduationResForm.academicYear = val;
      },
      showAttachment(titleAttachment){
        window.open(this.$until.url + '/' + titleAttachment)
      },
      downloadFile(){
        this.$http.get(`${this.$until.url}/graduateProgram/exportGraduateInfoStaff`,{
          params: this.graduationResForm
        }).then((res) => {
          var url = res.body.message
          try {
            var elemIF = document.createElement("iframe");
            elemIF.src = url;
            elemIF.style.display = "none";
            document.body.appendChild(elemIF);
          } catch (e) {
          }
        }, (err) => {

        })
      }
    }
  }
</script>


